//
//  FRIDCardViewController.m
//  LFCWarmSystem
//
//  Created by Kill on 16/4/28.
//  Copyright © 2016年 李福才. All rights reserved.
//

#import "FRIDCardViewController.h"

@interface FRIDCardViewController ()<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>{
    UITextField *myTextField;
}
@end

@implementation FRIDCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self uiInit];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)uiInit{
    UILabel *lblHeadView = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, TABLEVIEWCELLHEIGHT)];
    lblHeadView.text = NSLocalizedString(@"RFIDNum_Sample",@"RFID卡短信通知号码");
    lblHeadView.textColor = COLOR_MAINHEAD;
    lblHeadView.font = TABLEHEADFONT;
    lblHeadView.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lblHeadView];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10*WIDTHSCALE, lblHeadView.frame.origin.y+lblHeadView.frame.size.height+10*WIDTHSCALE, self.view.frame.size.width-10*2*WIDTHSCALE, TABLEVIEWCELLHEIGHT)];
    view.backgroundColor = TABLEVIEWCOLOR;
    view.layer.cornerRadius = 5.0;
    myTextField = [[UITextField alloc] initWithFrame:CGRectMake(10*WIDTHSCALE, view.frame.size.height/8.0, view.frame.size.width-10*2*WIDTHSCALE, view.frame.size.height*3/4.0)];
    myTextField.backgroundColor = TEXTFIELDCOLOR;
    myTextField.layer.cornerRadius = 5.0;
    myTextField.textColor = [UIColor whiteColor];
    myTextField.delegate = self;
    myTextField.placeholder = NSLocalizedString(@"PleaseEnterPhoneNum_Sample", @"  请输入电话号码");
    [myTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [myTextField setValue:TEXTFONT forKeyPath:@"_placeholderLabel.font"];
    [view addSubview:myTextField];
    [self.view addSubview:view];
}

#pragma mark -UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    textField.keyboardType = UIKeyboardTypeNumberPad;
}

-(void)rightAction:(id)sender{
    NSString *msgContect = [self languageMSG:@"SMS No.FRID tags(0-20Digits):"];
    msgContect = [NSString stringWithFormat:@"%@\n1.%@",msgContect,myTextField.text];
    [self showSMSPicker:msgContect];
}


- (NSString *)languageMSG:(NSString*)content{
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"mulLan" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *str = @"";
    if ((str= [data objectForKey:[NSString stringWithFormat:@"CRFIDCardPhoneSMS_%@ ",self.modelPhone.language]])) {
        content = str;
        
    }
    return [[content componentsSeparatedByString:@"\\r"] firstObject];
}
#pragma mark-Send Message
-(void)showSMSPicker:(NSString *)MSGContent{
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
    if (messageClass != nil) {
        // Check whether the current device is configured for sending SMS messages
        if ([messageClass canSendText]) {
            MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
            picker.recipients = [NSArray arrayWithObjects:self.modelPhone.phoneNumber, nil];
            picker.messageComposeDelegate = self;
            picker.body = MSGContent;
            [self presentViewController:picker animated:YES completion:^{
            }];
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"DeviceCantMSG", @"设备没有短信功能")  message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"Close_Sample", @"  关闭") otherButtonTitles: nil];
            [alert show];
        }
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"VersionProblem", @"iOS版本过低,iOS4.0以上才支持程序内发送短信") message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"Close_Sample", @"  关闭") otherButtonTitles: nil];
        [alert show];
    }
}


@end
